<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //使用原型+构造函数创建对象
    function Person(id,name,age){
        this.id=id
        this.name=name
        this.age=age
    }
    //使用构造函数Person找原型对象
    let proto=Person.prototype
    console.log(proto);
    //给原型对象添加一个属性hobby
    proto.hobby=['lol','qq飞车']
    console.log(proto);
    //给原型添加一个函数返回当前对象的属性
    proto.info=function(){
        return this.id+","+this.name+","+this.age
    }

    //创建实例对象
    let p=new Person(1,"tom",20)
    let p1=new Person(2,"tom1",20)
    let p2=new Person(3,"tom2",20)
    console.log(p.info())
     //给String的原型对象添加方法，作用是去除首尾空格
  String.prototype.trims = function() {
    return this.trim()
  }
  console.log("  hello_proto ".trims())

  //给date添加一个格式化方法
  Date.prototype.formateDate = function() {
    let year = this.getFullYear()
    //...
    return '这是格式好的日期'
  }
  let date = new Date()
  let str = date.formateDate()
  console.log(str)
  let date1 = new Date()
  console.log(date1.getFullYear())
</script>
</html>